//************************************************
//  *Author：jxx
//  *QQ：283591387
//  *自定义业务逻辑扩展
//************************************************
import { mapMutations } from 'vuex';
import extend from './q_fittings_deliveryExtend.js';
import options from './q_fittings_deliveryOptions.js';
import detailOptions from '../q_fittings_deliveryList/q_fittings_deliveryListOptions.js';
export default function () {
	return {
		data() {
			let _options = options();
			_options.extend = extend;
			_options.detailOptions = detailOptions();
			return {
				options: _options,
			};
		},
		methods: {
			...mapMutations(['setSalesContractDataStore', 'setPageIDStore']),
			onInited() {
				this.editFormOptions.forEach((item) => {
					if (item.field == 'Operations_contract_sub') {
						item.testVal = '点击选择运维合同';
						item.required = true;
						item.focusUrl = '/operationsinfo/q_operations_contract/q_operations_contract';
						// item.onFocus=(e)=>{
						// 	console.log("this.editFormFields",this.editFormFields);
						// 	uni.navigateTo({
						// 		url:"/operationsinfo/q_fittings_delivery/q_fittings_delivery"
						// 	})
						// }
					}
				});
			},
			formatter(row, column, index) {
				//自定义格式化
				// if (column.field == 'Attachment' && row[column.field]) {
				// 	// console.log("row[column.field]",row[column.field]);
				// 	const arr = row[column.field].split(',');
				// 	// console.log("arr",arr);
				// 	const regex = new RegExp(/\//g, 'g');
				// 	let index = null;
				// 	let nameArr = [];
				// 	arr.forEach((item) => {
				// 		const itemName = item.split('/');
				// 		const name = itemName[itemName.length - 1];
				// 		nameArr.push(name);
				// 	});
				// 	return `<span style="color: #0189ff;padding: 2px 10px;
				//          font-size: 10px;"> ${nameArr.join(',')}</span>`;
				// }
				return '';
			},
			rowClick(index, row, column) {
				//行点击事件(默认触发编辑)
				this.setPageIDStore(row.Fittings_delivery);
				let url = '/operationsinfo/q_fittings_delivery/Detail/Detail?operationsinfo=' + row.Fittings_delivery;
				uni.navigateTo({
					url: url
				});
				return false;
			},
			cellClick(index, row, column) {
				//单元格击事件(默认触发编辑)
				//仅onInited中设置：this.direction = "horizontal", this.columns的字段设置为click=true后生效
				return true;
			},
			rowButtons(index, row) {
				//列表显示的按钮
				//自定义按钮,仅onInited中设置：this.direction = "list"后生效
				// return [{
				// 	text: "测试",
				// 	icon: "edit-pen",
				// 	type: "primary",
				// 	plain:true,
				// 	shape:"circle",
				// 	disabled: false
				// },{
				// 	text: "删除",
				// 	icon: "trash",
				// 	type: "error",
				// 	plain:true,
				// 	shape:"circle",
				// 	//shape:"",//square、circle
				// 	disabled: false
				// }];
				let buttonList = [];
				let pages = getCurrentPages();
				// console.log('pages', pages);
				let prevPage = pages[pages.length - 2];
				if (pages.length >= 3 && prevPage.route == 'pages/addPage/addPage' && row.AuditStatus === 1) {
					buttonList.push({
						text: '选择发货单',
						type: 'success ',
						shape: 'circle'
					});
				}
				if (row.AuditStatus === 0) {
					buttonList.push({
						text: '审核',
						type: 'error',
						shape: 'circle'
					});
					buttonList.push({
						text: '编辑',
						type: 'warning',
						shape: 'circle'
					});
				} else {
					buttonList.push({
						text: '查看审核',
						type: 'primary',
						shape: 'circle'
					});
				}
				//返回查看审批按钮
				return buttonList;
			},
			rowButtonClick(btn, index, row) {
				//列表显示的按钮点击事件
				if (btn.text == '编辑') {
					// this.$toast('编辑，跳到新增页面');
					console.log('编辑row', row);
					uni.setStorageSync('q_fittings_delivery', row);
					const optionsObj = {
						// editFormFields: this.options.editFormFields,
						editFormOptions: this.options.editFormOptions,
						detailColumns: this.options.detailOptions.columns,
						detailtable: this.options.table
					};
					uni.setStorageSync('optionsObj', JSON.stringify(optionsObj));
					uni.navigateTo({
						url: '/pages/addPage/addPage?biaoming=q_fittings_delivery&currentAction=Update&ID=Fittings_delivery&zibiaoming=q_goods_inventory_warehouse_xm'
					});
					return;
				}
				if (btn.text == '选择发货单') {
					// 清空明细表
					this.$store.commit('clearOperations_recycleList');
					const obj = JSON.stringify({
						Fittings_delivery: row.Fittings_delivery,
						Fittings_delivery_sub: row.Voucher_sub,
						Client_name: row.Client_name,
						Site: row.Site
					});
					uni.setStorageSync('obj', obj);
					uni.navigateBack();
					return;
				}
				this.setSalesContractDataStore({ workTable: 'q_fittings_delivery', tableKey: row.Fittings_delivery });
				try {
					uni.navigateTo({
						url: `/operationsinfo/q_fittings_delivery/q_fittings_deliveryAduit?workTable=q_fittings_delivery&&tableKey=` + row.Fittings_delivery
					});
				} catch (e) {
					//TODO handle the exception
					console.log(e);
				}
			},
			searchBefore(params) {
				//查询前
				return true;
			},
			updateBefore(formData) {
				//更新保存前操作
				return true;
			},
			addBefore(formData) {
				//新建保存前操作
				return true;
			},
			searchFormOnChange(field, value) {
				//查询弹出框下拉框或日期选中事件
				//if(field=="字段"){
				// 	console.log(value)
				//}
			},
			editFormOnChange(field, value) {
				//新建编辑弹出框下拉框或日期选中事件
				//if(field=="字段"){
				// 	console.log(value)
				//}
			}
		}
	};
}
